package com.swt.gap.controller;


import com.swt.gap.common.graph.GraphNeo4jVO;
import com.swt.gap.model.vo.ParseEntityVO;
import com.swt.gap.model.vo.element.ElementParseVO;
import com.swt.gap.service.CorpusService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "文档提取,旧版,废弃")
@RestController
@RequestMapping("/doc-data")
@Slf4j
@Deprecated
public class CorpusController {

    @Autowired
    private CorpusService corpusService;

    @GetMapping("/text-entity")
    @ApiOperation(value = "要素提取", notes = "要素提取")
    @ApiImplicitParam(name = "savedFileName", dataType = "String",paramType = "query", value = "提取内容文件名")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = ParseEntityVO.class)})
    public ResponseEntity getElement(@RequestParam String savedFileName){
        return ResponseEntity.ok(corpusService.parseEntity(savedFileName));
    }

    @GetMapping("/new/text-entity")
    @ApiOperation(value = "新版要素提取", notes = "新版要素提取")
    @ApiImplicitParam(name = "savedFileName", dataType = "String",paramType = "query", value = "提取内容文件名")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = ElementParseVO.class)})
    public ResponseEntity extractAndParse(@RequestParam String savedFileName){
        try {
            return ResponseEntity.ok(corpusService.extractCombinedEvents(savedFileName));
        } catch (Exception e) {
            e.printStackTrace();
//            ElementParseVO elementParseVO = new ElementParseVO();
//            List<ElementParseVO.EventExtractVO> eventExtract = corpusService.createDefaultForm();
//            elementParseVO.setEventExtractVOS(eventExtract);
//            return ResponseEntity.ok(elementParseVO);
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("提取出错");
        }

    }


    @PostMapping("/graph/{savedFileName}")
    @ApiOperation(value = "图谱展示", notes = "图谱展示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventExtractVOS", dataType = "array",paramType = "body", value = "提取的事件内容"),
            @ApiImplicitParam(name = "savedFileName", dataType = "String",paramType = "path", value = "提取内容文件名")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.class)})
    public ResponseEntity parseGraph(@RequestBody List<ElementParseVO.EventExtractVO> eventExtractVOS, @PathVariable String savedFileName){
        return ResponseEntity.ok(corpusService.parseGraph(eventExtractVOS, savedFileName));
    }


}
